from lin_base import *

def add_lin_month_zhe(paper,title,x0,y0,xend,font=unicode_font_36,
                    fgcolor=BLACK,lw=2):
    ecl_ras = g_share.ecl_ras
    layer=paper.add_layer(name='month_zhe')
    draw = layer.draw
    lines=[]
    texts=[]
    zxs=[]
    draw.text((x0-XM_TITLE,y0+YM_TEXT),title, font=font,fill=fgcolor)
    for j in range(360):
        ra = ecl_ras[j]
        #print(j,ra)
        if (j % 15)> 0:
            continue
        i = int(j / 15)
        ra_hr = ra/15
        xs=RA_to_xs(x0,xend, ra_hr)
        for x in xs:   
            si,sr = divmod(i,2)
            if sr!=0:
                zi = (si+ZHE_ST) % 12
                zx = ZHE[zi]
                #draw.text((x,y0+YM_TEXT),zx, font=font,fill=fgcolor)
                lines.append([(x,y0),(x,y0+YM_LONG)])
                texts.append(((x,y0+YM_TEXT),zx))
                if zx =='寅':
                    zxs.append(x)

    draw.rectangle([(zxs[0],y0),(zxs[1],y0+Y_MM)],fill=YELLOW)
    for xy in lines:
        draw.line(xy,fill=fgcolor,width=lw) 
    for xy,txt in texts:
        draw.text(xy,txt,font=font,fill=fgcolor)
    draw.line([(x0,y0),(xend,y0)],fill=BLACK,width=2)